{% from "usersite/macros/urls.html" import site_ipns_url %}

{% macro render_blog_post_tags(post, from_index=false) %}
  {% if post.tags %}
    <b>Tags</b>:

    {% for tag in post.tags %}

    {% if from_index %}
    <a href="bytag/{{ tag }}/index.html">{{ tag }}</a>
    {% else %}
    {{ tag }}
    {% endif %}

    {% endfor %}
  {% endif %}
{% endmacro %}

{# Adapted from lektor's macro #}
{% macro render_blog_post(post, from_index=false) %}
  <div class="blog-post">
  {% if from_index %}
    <h2 class="blog-title">
     <a href="posts/{{ post.postName }}/view">{{ post.title.en }}</a>
    </h2>

    {{ render_blog_post_tags(post, from_index=from_index) }}

    <p class="blog-meta">
      written by
      <a href="ipid://{{ post.didCreator|ipidExtract }}">
        <b>{{ post.author }}</b>
      </a> at {{ post.datePublished|dtclean }}
    </p>
  {% else %}
    <h2 class="blog-title">{{ post.title.en }}</h2>

    {{ render_blog_post_tags(post, from_index=from_index) }}

    <p class="blog-meta">
      written by
      <a href="ipid://{{ post.didCreator|ipidExtract }}">
        <b>{{ post.author }}</b>
      </a> at {{ post.datePublished|dtclean }}
    </p>

  {% endif %}

    <div class="blog-post-body">
      <p>
        {{ post.body.en|markdown }}
      </p>
    </div>
  </div>
{% endmacro %}
